import router from '../../router/index'
import NProgress from 'nprogress' // progress bar

NProgress.configure({showSpinner: false}) // NProgress Configuration
const whiteList = ['/login','/404','/print'] // 不重定向白名单
router.beforeEach((to,from,next)=>{


    if(sessionStorage.getItem('token')){
        NProgress.start();

    }else{
        console.log(111)
        if (whiteList.indexOf(to.path) !== -1) {
            next()
        } else {
            next('/login')
        }
    }

})
router.onError(error => {
    console.log(error, '路由错误')
    router.replace('/404')
    NProgress.done() // 结束Progress

})

router.afterEach(() => {
    NProgress.done() // 结束Progress
})
